include ../includes/head
block content
    include ../includes/header
.container-fluid
    .row
        include ../includes/slide
        .col-sm-9.col-sm-offset-3.col-md-10.col-md-offset-2.main
          - if (!denied)
            h1.page-header 添加摄像机
            .row.placeholders
                //form.form-horizontal(role='form' action='/equipment/add' method='post')
                form.form-horizontal(role='form')
                    div.form-group
                        label.col-sm-5.control-label(for='name') 摄像机名称
                        div.col-sm-3
                            input.form-control(id='name' name='name' type='text' placeholder='摄像机名称' required)
                    div.form-group
                        label.col-sm-5.control-label(for='equip_id') 摄像机ID
                        div.col-sm-3
                            input.form-control(id='equip_id' name='equip_id' type='text' placeholder='摄像机ID' required)
                    div.form-group
                        label.col-sm-5.control-label(for='key') 摄像机key
                        div.col-sm-3
                            input.form-control(id='key' name='key' type='text' placeholder='摄像机key' required)
                    div.form-group
                        label.col-sm-5.control-label(for='project_id') 所属项目
                        div.col-sm-3
                            select.form-control(id='project_id' name='project_id' type='text' placeholder='所属项目' required)
                                if(result)
                                    each item in result
                                        option(value='#{item.id}') #{item.name}
                    div.form-group
                        label.col-sm-5.control-label
                        div.col-sm-1
                            //button.sub_btn.sub_left_btn#submitBtn(type='submit') 提交
                            button.sub_btn.sub_left_btn#submitBtn(type='button') 提交
                        div.col-sm-1
                            a(href='/equipment/list')
                                button.sub_btn.sun_right_btn(type='button') 取消
          - else
            h2.page-header 没有权限

include ../includes/footer
    //AJAX调用添加接口
script(type='text/javascript').
    $("#submitBtn").click(function () {
        var camera = new Object();
        camera.name = $("#name").val();
        camera.key = $("#key").val();
        camera.equip_id = $("#equip_id").val();
        camera.user_id = getString("userId");
        camera.project_id = $("#project_id").val();
        //处理时间
        camera.create_time = getTime();
        if ($("#name").val() == "") {
            return Tip.warning("请输入摄像机名称")
        }
        if ($("#equip_id").val() == "") {
            return Tip.warning("请输入摄像机ID")
        }
        if ($("#key").val() == "") {
            return Tip.warning("请输入摄像机KEY")
        }
        if ($("#project_id").val() == "") {
            return Tip.warning("请选择一个项目")
        }
        $.ajax({
            method: "POST",
            url: '/camera/add',
            data: camera,
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    Tip.alert("add", "camera", "success");
                } else {
                    Tip.alert("add", "camera", "error");
                }

            },
            error: function (data) {
                Tip.alert("add", "camera", "error");
            }
        });
    });